package userserv

import (
	"task"
	//"fmt"
	"log"
	"net/http"
)

func onStopTask(w http.ResponseWriter, r *http.Request) {
	var account string
	account = r.Header.Get("account")

	log.Printf("stopTask, account:%s\n", account)

	var taskId = r.URL.Query().Get("tid")
	log.Println("stopTask, taskId:", taskId)

	errcode := checkTaskOfAccount(account, taskId)
	if errcode != 0 {
		replyError(w, errcode)
		return
	}

	errcode = task.Mgr.StopTask(account, taskId)
	if errcode == 0 {
		w.WriteHeader(200)
	} else {
		replyError(w, errcode)
	}
}

func init() {
	myMux.muxHandlers.HandleFunc("/stopTask", onStopTask)
}
